package display.tabs;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;

import display.InventoryData;
import display.MBSUpdate;

/**
 * Represents the settings tab.
 * @author Steve
 *
 */
public class SettingsTab extends Tab {

	private JComboBox termBox = new JComboBox();
	private JButton MBS = new JButton("MBS Update"), invImport = new JButton("Inventory Import");
	private MyActionListener mal;
	
	public SettingsTab(InventoryData in) {
		super(in);
		
		mal = new MyActionListener();
		
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{163, 0};
		gridBagLayout.rowHeights = new int[]{23, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		termBox.setActionCommand("tb");
		termBox.setEditable(false);
		termBox.addActionListener(mal);
		
		GridBagConstraints gbc_lblTerm = new GridBagConstraints();
		gbc_lblTerm.anchor = GridBagConstraints.WEST;
		gbc_lblTerm.insets = new Insets(0, 0, 0, 5);
		gbc_lblTerm.gridx = 0;
		gbc_lblTerm.gridy = 0;
		GridBagConstraints gbc_termBox = new GridBagConstraints();
		gbc_termBox.insets = new Insets(0, 0, 5, 0);
		gbc_termBox.gridy = 0;
		gbc_termBox.gridx = 0;
		add(termBox, gbc_termBox);
		
		GridBagConstraints gbc_MBS = new GridBagConstraints();
		gbc_MBS.insets = new Insets(0, 0, 5, 0);
		gbc_MBS.anchor = GridBagConstraints.NORTH;
		gbc_MBS.gridx = 0;
		gbc_MBS.gridy = 1;
		add(MBS, gbc_MBS);
		
		MBS.setActionCommand("MBS");
		MBS.addActionListener(mal);
		
		GridBagConstraints gbc_btnInventoryImport = new GridBagConstraints();
		gbc_btnInventoryImport.gridx = 0;
		gbc_btnInventoryImport.gridy = 2;
		add(invImport, gbc_btnInventoryImport);
		
		invImport.setActionCommand("InvImp");
		invImport.addActionListener(mal);
	}
	
	public void initTerms() {
		//termBox.addActionListener(al);
		
		termBox.setModel(new DefaultComboBoxModel(inv.initTerms()));
		termBox.addItem("New Term");
	}
	
	private class MyActionListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent arg0) {
			// TODO Auto-generated method stub
			String command = arg0.getActionCommand();
			if (command.equalsIgnoreCase("MBS"))
				MBS();
			else if (command.equalsIgnoreCase("InvImp"))
				InvImp();
			else if (command.equalsIgnoreCase("tb"))
				TB();
		}
		
		private void MBS() {
			MBSUpdate mu = new MBSUpdate();
			mu.setVisible(true);
		}
		private void InvImp() {}
		private void TB() {}
		
	}
	
}
